#include <iostream>
#include <string>
#include <vector>

using namespace std;

class PowerOutage
{
public:
    int estimateTimeOut(vector <int> fromJunction, vector <int> toJunction, vector <int> ductLength)
    {
		int result = 0;
		for(int i=0; i<fromJunction.size(); i++)
		{
			result += ductLength.at(i);
		}
		result *= 2;
		result -= dfs(0, fromJunction, toJunction, ductLength);
		return result;
    }
private:
	int dfs(int now, vector<int> &from, vector<int> &to, vector<int> &duct)
	{
		int result = 0;
		for(int i=0; i<from.size(); i++)
		{
			if(from.at(i) == now)
			{
				result = max(result, dfs(to.at(i), from, to, duct) + duct.at(i));
			}
		}
		return result;
	}
};
/*
 * Since every routine from root every traverse twice, except the one last be traversed,
 * the mission become to be find the max cost of all the routines.
 * Note: there is no loop here. Bring a lot of convenience here.
 * */
